home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / pctecap.arc / LEXSEARC.ASM < prev    next >
Assembly Source File  |  1986-03-15  |  2KB  |  79 lines

  1. ; ROUTINE TO SEARCH FOR A WORD IN AN ORDERED LIST OF WORDS
  2. ;
  3. lexsearch    proc    far
  4. ;
  5.     push    si        ; save registers
  6.     push    di
  7.     push    cx
  8. ;
  9. ; point to beginning of list and get its length
  10.     mov    di,bp        ; beginning of list
  11.     mov    cx,[di]        ; get length
  12.     inc    di
  13.     inc    di
  14. ;
  15. ; compare source word with words in the list
  16. ;
  17. lexsearch1:
  18. ;
  19.     mov    dx,di        ; save beginning of dest word
  20. ;
  21. ; forward direction
  22.     cld            ; forward direction
  23. ;
  24. ; point to beginning of source
  25.     mov    si,bx        ; point to beginning of source
  26.     inc    si
  27.     inc    si
  28. ;
  29. ; compare source word with a word of the list
  30. lexsearch2:
  31. ;
  32. ; check for end of list
  33.     jcxz    lexsearch5    ; end of list - insert it
  34. ;
  35. ; set up carriage return as character for scanning 
  36.     mov    al,13        ; scan for carriage return
  37. ;
  38. ; check for end of source word
  39.     cmp    [si],al        ; source byte = carriage return?
  40.     je    lexsearch4    ; end of source word found
  41. ;
  42. ; check for end of destination word
  43.     cmp    es:[di],al    ; dest byte = carriage return?
  44.     je    lexsearch3    ; no match - go to next word
  45. ;
  46. ; compare character by character
  47.     dec    cx
  48.     cmpsb            ; check for match
  49.     je    lexsearch2    ; matched - check next character
  50.     jb    lexsearch5    ; too high - this is the place
  51. ;
  52. ; scan for next carriage return
  53. lexsearch3:
  54.     repnz    scasb        ; scan until carriage return
  55.     jmp    lexsearch1    ; next word
  56. ;
  57. ; end of source word was found
  58. lexsearch4:
  59.     cmp    [di],al        ; dest character = carriage return?
  60.     je    lexsearch6    ; end of destination word?
  61. ;
  62. ; found a spot to insert the word
  63. lexsearch5:
  64.     mov    al,0FFh        ; success
  65.     jmp    lexsearchexit
  66. ;
  67. ; word is already present
  68. lexsearch6:
  69.     mov    al,00h        ; already there
  70.     jmp    lexsearchexit
  71. ;
  72. lexsearchexit:
  73.     pop    cx        ; restore registers
  74.     pop    di
  75.     pop    si
  76.     ret
  77. ;
  78. lexsearch    endp
  79.